import java.util.Scanner;

/**
 *
 输入一个单向链表和一个节点的值，从单向链表中删除等于该值的节点，删除后如果链表中无节点则返回空指针。
 *
 *
 * @author: YuanChilde
 * @date: 2020-02-17 8:01
 * @version: 1.0
 * Modification History:
 * Date    Author      Version     Description
 * -----------------------------------------------------------------
 * 2020-02-17 8:01    YuanChilde     1.0        新增
 */
public class Demo20 {
    static class Node{
        int val;
        Node next;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt())
        {
            int n = sc.nextInt();
            int headVal = sc.nextInt();
            Node head = new Node();
            head.val = headVal;
            head.next = null;
            for(int i = 0;i<n-1;i++)
            {
                int newVal = sc.nextInt();
                int targetVal = sc.nextInt();
                addNode(newVal,targetVal,head);
            }
            int delVal = sc.nextInt();
            head = delNode(delVal,head);
            printNode(head);
        }
        sc.close();
    }

    private static void addNode(int newVal,int targetVal,Node head){
        Node current = head;
        while(current!=null){
            if (current.val == targetVal){
                Node newNode = new Node();
                newNode.val = newVal;
                newNode.next = current.next;
                current.next = newNode;
                break;
            }
            current = current.next;
        }
    }

    private static Node delNode(int delVal,Node head){
        if(delVal == head.val){
            Node returnNode = head.next;
            head.next = null;
            return returnNode;
        }else{
            Node current = head;
            while(current.next!=null){
                if(delVal == current.next.val){
                    current.next = current.next.next;
                    break;
                }
                current = current.next;
            }
            return head;
        }
    }

    private static void printNode(Node head){
        StringBuilder sb = new StringBuilder();
        while(head!=null){
            sb.append(head.val).append(" ");
            head = head.next;
        }
        System.out.println(sb.toString());
    }
}
